<?php
/* 
 * FilePath: rwmsp-app\Consumer.php
 * Created: lijianwei 2021-05-26 11:01:16
 * -----
 * Last Modified: lijianwei 2021-05-27 13:35:09
 * -----
 * Copyright (c) 2016-2021 Rongwen Tech Ltd.
 * -----
 */
require './vendor/autoload.php';
//生产消费者模式 demo
use longlang\phpkafka\Producer\Producer;
use longlang\phpkafka\Producer\ProducerConfig;

$msg_type = 'test'; //topic_id
$msg = [
    'msg_type' => $msg_type,
    'content' => 'xx红绿灯旁边有一科大树倒下, 并且挡住路, 继续处理, 请尽快安排',
];
$msg['msg_id'] = uniqid('', true);
$msg_json = json_encode($msg, JSON_UNESCAPED_UNICODE);

$config = new ProducerConfig();
$config->setBootstrapServer('127.0.0.1:9092');
$config->setUpdateBrokers(true);
$config->setAcks(-1);
$producer = new Producer($config);

$producer->send($msg_type, $msg_json, $msg['msg_id']);
